Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Update implementation of ndim property of transforms #197

Merged
merged 14 commits into from
Apr 19, 2024

Conversation

jmarabotto
Copy link
Contributor

Resolves: #196 .

commandline_for_tests.txt Outdated Show resolved Hide resolved
Julien Marabotto added 3 commits April 18, 2024 16:50
Tranformbase -> now raises TypeError; Affine -> overshadows TransformBase's property and returns self._matrix.ndim + 1. To be applied to LinearTransformMapping (Currently TypeError)
Added two tests for ndim: assert nitl.Affine().ndim == 3; assert nitl.LinearTransformsMapping([nitl.Affine()]).ndim == 4 .
nitransforms/linear.py Outdated Show resolved Hide resolved
@oesteban oesteban merged commit 592f91b into nipy:master Apr 19, 2024
6 checks passed
@jmarabotto jmarabotto deleted the Implement_ndim branch April 19, 2024 08:32
Comment on lines +148 to +149
"""Access the internal representation of this affine."""
return self._matrix.ndim + 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely -1? A 4x4 affine represents a transform in 3D space, and nothing intelligible I'm aware of in 5 dimensions.

Also this docstring is off.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, it's a 2D matrix, so this works out to 3, but does so in all cases. What you actually want is self._matrix.shape[0] - 1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work for 2D transforms. But it does work for >2D:

  • self._matrix is 4x4 in 3D transforms (+1)
  • self._matrix is tx4x4 in 4D transforms (3D + t)
  • self._matrix is tx4x4x2 in 5D transforms (3D + t + complex numbers).

5D could become "a thing" when we want to realign 3D+t images reconstructed with magnitude and phase (or complex). This looks more plausible than generalization to 2D images (2D, 2D+t, 2D+t+part).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so we're not considering e.g., a 5x5 affine matrix for transforms of 4D spaces, but a collection of 4x4 affines for a collection of 3D volumes.

If you want to be really general, you could treat it as self._matrix.shape[0] + self._matrix.ndim - 3, which would handle collections of any number of ND affine spaces. But I'm okay keeping this simplification and assuming 3D volumes for now.

As an aside: I don't really understand why you would treat the real and imaginary parts of complex numbers as being an extra dimension in this context. The interpolation would need to account for the complex plane (though on first thought, independent interpolation of real and imaginary components should work...) , but I don't see why the transform would.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so we're not considering e.g., a 5x5 affine matrix for transforms of 4D spaces, but a collection of 4x4 affines for a collection of 3D volumes.

Correct

I don't really understand why you would treat the real and imaginary parts of complex numbers as being an extra dimension in this context.

The fact that this ndim could be 5D does not mean that the transform should use all the dimensions. I agree you (in principle) don't want to interpolate in between imaginary and real part.

If you want to be really general, you could treat it as self._matrix.shape[0] + self._matrix.ndim - 3, which would handle collections of any number of ND affine spaces. But I'm okay keeping this simplification and assuming 3D volumes for now.

I think your implementation is better; why keep the simplification once you've written a better alternative down here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transforms should implement an ndim property
3 participants